{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f8e3a67",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fc64ecd5",
   "metadata": {},
   "outputs": [],
   "source": [
    "#OPENOCD_PATH=r\"C:\\Users\\adewa\\OpenOCD\\bin\\openocd.exe\"\n",
    "OPENOCD_PATH=\"../../../xpack-openocd-0.11.0-3/bin/openocd\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e9418f7d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b005cb6",
   "metadata": {},
   "outputs": [],
   "source": [
    "import chipwhisperer as cw\n",
    "scope = cw.scope()\n",
    "serialnumber = scope.sn\n",
    "target = cw.target(scope)\n",
    "scope.default_setup()\n",
    "scope.dis()\n",
    "#scope.enable_MPSSE()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "81dbcd25",
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "cd ../../firmware/mcu/simpleserial-aes\n",
    "make PLATFORM=CW308_K82F CRYPTO_TARGET=TINYAES128C SS_VER=SS_VER_2_1 -j"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63609572",
   "metadata": {},
   "outputs": [],
   "source": [
    "import subprocess, sys\n",
    "commands = [OPENOCD_PATH, '-f', \"../../cw_openocd.cfg\", '-c', \"transport select jtag\", '-c', \n",
    "            \"ftdi vid_pid 0x2b3e 0xace2\", '-c', 'adapter serial {}'.format(serialnumber), '-f', \"target/kx.cfg\", '-c', \"init\", '-c', \"reset halt\", '-c', \n",
    "            \"flash write_image erase ../../firmware/mcu/simpleserial-aes/simpleserial-aes-CW308_K82F.elf\",\n",
    "            '-c', \"shutdown\"]\n",
    "try:\n",
    "    x = subprocess.run(commands, check=True, capture_output=True)\n",
    "except Exception as x:\n",
    "    print(x.stderr.decode())\n",
    "    print(x.stdout.decode())\n",
    "    raise x\n",
    "print(x.stderr.decode())\n",
    "print(x.stdout.decode())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "306c73f2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
